package com.xinqi.modules.exam.task.controller.web;

/**
 * @author linkai
 * @date 2023/9/6
 */

import com.xinqi.common.base.response.R;
import com.xinqi.common.redis.topic.TopicHelp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;

/**
 * WEB-主题消息
 *
 * @author: linkai
 * @date: 2023/07/08
 */
@Tag(name = "WEB-主题消息", description = "WEB-主题消息")
@RestController
@RequestMapping("/web/redis-topic")
@RequiredArgsConstructor
public class TopicHelpController {
    private final TopicHelp topicHelp;

    /**
     * 新增延时队列
     */
    @Operation(summary = "新增主题消息")
    @PostMapping("/add")
    public R<Boolean> insert(@RequestBody RedisTopicDTO dto) {
        topicHelp.publish(dto.getTopic(), dto.getMessage());
        return R.data(true);
    }

    @Data
    public static class RedisTopicDTO implements Serializable {
        private String topic;
        private Long message;
    }

}
